package com.xiaoshuidi.cloud.module.finance.mq.producer;

import com.xiaoshuidi.cloud.framework.common.core.KeyValue;
import com.xiaoshuidi.cloud.framework.mq.core.RocketMQMessageDelayLevel;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageConst;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class InvoiceQueryDelayProducer {
    @Resource
    private StreamBridge streamBridge;

    public void send(String seqNo) {
        log.info("发送查询发票结果延时消息: {}", seqNo);
        streamBridge.send("invoiceQueryDelay-out-0", MessageBuilder
                // 参数会json序列化成对象, 原始类型反序列化会报错, 整成对象
                .withPayload(new KeyValue<>("seqNo", seqNo))
                .setHeader(MessageConst.PROPERTY_DELAY_TIME_LEVEL, RocketMQMessageDelayLevel._30s));
    }

}
